package pers.xiaojun.boot.common.validation.validator;

import cn.hutool.core.util.StrUtil;
import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;
import pers.xiaojun.boot.common.util.RegexUtils;
import pers.xiaojun.boot.common.validation.constraints.Mobile;

/**
 * 手机号校验器
 *
 * @author xiaojun
 * @since 2025-11-19
 */
public class MobileValidator implements ConstraintValidator<Mobile, String> {

    @Override
    public boolean isValid(String mobile, ConstraintValidatorContext constraintValidatorContext) {
        // 为 null 不判断
        if (mobile == null) {
            return true;
        }
        if (mobile.isEmpty()) {
            return false;
        }
        return RegexUtils.isMobile(mobile);
    }
}
